import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Login extends JFrame implements ActionListener {
    JPanel panelTop,panelCenter,panelBottom;
    JLabel image,labelName,labelAge,labelSex,labelHobby,labelIntroduction;
    JTextField textName,textAge;
    JRadioButton male,female;
    ButtonGroup group;
    JCheckBox c,java;
    JTextArea intro;
    JScrollPane scrollPane;
    JButton btn_ok,btn_reset;

    public Login(){
        setSize(160,360);
        setTitle("注册");
        setLocationRelativeTo(null);
        panelTop = new JPanel();
        panelCenter = new JPanel();
        panelBottom = new JPanel();
//上半
        ImageIcon logo = new ImageIcon("welcome.gif");
        image = new JLabel(logo);
        panelTop.add(image);
//中间
        labelName = new JLabel("姓  名");
        labelAge = new JLabel("年  龄");
        labelSex = new JLabel("性  别");
        labelHobby = new JLabel("擅长");
        labelIntroduction = new JLabel("自我介绍");
        textName = new JTextField(10);
        textAge = new JTextField(10);
        male = new JRadioButton("男");
        female = new JRadioButton("女");
        group = new ButtonGroup();
        c = new JCheckBox("C");
        java = new JCheckBox("Java");
        intro = new JTextArea("自我介绍",5,6);
        scrollPane = new JScrollPane(intro,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        group.add(male);
        group.add(female);

        panelCenter.add(labelName);
        panelCenter.add(textName);
        panelCenter.add(labelAge);
        panelCenter.add(textAge);
        panelCenter.add(labelSex);
        panelCenter.add(male);
        panelCenter.add(female);
        panelCenter.add(labelHobby);
        panelCenter.add(c);
        panelCenter.add(java);
        panelCenter.add(labelIntroduction);
        panelCenter.add(scrollPane);

//下半
        btn_ok = new JButton("确定");
        btn_reset = new JButton("重置");

        panelBottom.add(btn_ok);
        panelBottom.add(btn_reset);
        add(panelTop, BorderLayout.NORTH);
        add(panelCenter,BorderLayout.CENTER);
        add(panelBottom,BorderLayout.SOUTH);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        btn_ok.addActionListener(this);
        btn_reset.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==btn_ok){
            //确定被点击
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append("姓名: " + textName.getText() + ",");
            stringBuffer.append("年龄: " + textAge.getText() + ",");
            if(male.isSelected()){
                stringBuffer.append("性别: 男,");
            }else stringBuffer.append("性别: " + female.getText() + ",");
            stringBuffer.append("擅长: ");
            if(c.isSelected()) stringBuffer.append("c ");
            if(java.isSelected()) stringBuffer.append("java ");
            stringBuffer.append(",自我介绍: " + intro.getText());
            JOptionPane.showMessageDialog(this,stringBuffer,"INFORMATION_MESSAGE",JOptionPane.INFORMATION_MESSAGE);

        }else {
            //重置按钮被点击
            textName.setText("");
            textAge.setText("");
            male.setSelected(false);
            female.setSelected(false);
            c.setSelected(false);
            java.setSelected(false);
            intro.setText("");

        }
    }
}


